#include "../../../odb/user.hxx"
#include "user-odb.hxx"
#include "../../../common/mysql_user.hpp"
#include <gflags/gflags.h>

DEFINE_bool(run_mode, false, "程序的运行模式，false-调试；true-发布");
DEFINE_string(log_file, "", "发布模式下，用于指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下，用于指定日志输出等级");


void insert(ChatSystem::UserTable& user_table)
{
    std::shared_ptr<ChatSystem::User> user1(new ChatSystem::User("uid1", "昵称1", "123456"));
    std::shared_ptr<ChatSystem::User> user2(new ChatSystem::User("uid2", "15566667777"));
    user_table.insert(user1);
    user_table.insert(user2);
}

void update_by_id(ChatSystem::UserTable& user_table)
{
    auto user = user_table.select_by_user_id("uid1");
    user->description("我是一个风一样的男人!");
    user_table.update(user);
}

void update_by_phone(ChatSystem::UserTable& user_table)
{
    auto user = user_table.select_by_phone("15566667777");
    user->description("哥只是个传说！");
    user_table.update(user);
}

void update_by_nickname(ChatSystem::UserTable& user_table)
{
    auto user = user_table.select_by_nickname("uid2");
    user->password("1233455334456");
    user_table.update(user);
}

void select_users(ChatSystem::UserTable& user_table)
{
    std::vector<std::string> id_lists;
    id_lists.push_back("uid1");
    id_lists.push_back("uid2");
    auto users = user_table.select_multi_users(id_lists);
    for(auto& user : users)
    {
        std::cout << user.nickname() << std::endl;
    }
}

int main(int argc, char* argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    ChatSystem::InitLogger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);

    auto db = ChatSystem::ODBFactory::create("root", "zhi204071", "127.0.0.1", "chatsystem", "utf8", 0, 1);
    ChatSystem::UserTable user(db);

    // insert(user);

    // update_by_id(user);

    // update_by_phone(user);

    // update_by_nickname(user);

    select_users(user);
    return 0;
}